<?xml version='1.0' encoding='iso-8859-1'?>
<!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
	<head>
		<title>
			int6kbaud.c
			</title>
		<meta http-equiv='content-type' content='text/html;iso-8859-1'/>
		<meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
		<meta name='author' content='cmaier@cmassoc.net'/>
		<meta name='robots' content='noindex,nofollow'/>
		<link href='toolkit.css' rel='stylesheet' type='text/css'/>
		</head>
	<body>
		<div class='headerlink'>
			[<a href='int64host.c.html' title=' int64host.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='int6kboot.c.html' title=' int6kboot.c '>NEXT</a>]
			</div>
<pre>
/*====================================================================*
 *
 *   Copyright (c) 2013 Qualcomm Atheros, Inc.
 *
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or 
 *   without modification, are permitted (subject to the limitations 
 *   in the disclaimer below) provided that the following conditions 
 *   are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials 
 *     provided with the distribution.
 *
 *   * Neither the name of Qualcomm Atheros nor the names of 
 *     its contributors may be used to endorse or promote products 
 *     derived from this software without specific prior written 
 *     permission.
 *
 *   NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE 
 *   GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE 
 *   COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR 
 *   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 *   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 *   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *
 *   int6kbaud.c - Atheros Serial Line Device Manager;
 *
 *
 *   Contributor(s):
 *      Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *   system header files;
 *--------------------------------------------------------------------*/

#include &lt;unistd.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;limits.h&gt;

#if defined (WIN32)
#elif defined (__linux__)
#	include &lt;termios.h&gt;
#elif defined (__APPLE__)
#	include &lt;termios.h&gt;
#elif defined (__OpenBSD__)
#	include &lt;termios.h&gt;
#else
#error &quot;Unknown Environment&quot;
#endif

/*====================================================================*
 *   custom header files;
 *--------------------------------------------------------------------*/

#include &quot;../tools/getoptv.h&quot;
#include &quot;../tools/putoptv.h&quot;
#include &quot;../tools/number.h&quot;
#include &quot;../tools/memory.h&quot;
#include &quot;../tools/endian.h&quot;
#include &quot;../tools/symbol.h&quot;
#include &quot;../tools/files.h&quot;
#include &quot;../tools/flags.h&quot;
#include &quot;../tools/error.h&quot;
#include &quot;../tools/types.h&quot;
#include &quot;../serial/serial.h&quot;
#include &quot;../plc/plc.h&quot;

/*====================================================================*
 *   custom source files;
 *--------------------------------------------------------------------*/

#ifndef MAKEFILE
#include &quot;../tools/getoptv.c&quot;
#include &quot;../tools/putoptv.c&quot;
#include &quot;../tools/version.c&quot;
#include &quot;../tools/uintspec.c&quot;
#include &quot;../tools/basespec.c&quot;
#include &quot;../tools/synonym.c&quot;
#include &quot;../tools/todigit.c&quot;
#include &quot;../tools/error.c&quot;
#include &quot;../tools/checksum32.c&quot;
#include &quot;../tools/hexencode.c&quot;
#include &quot;../tools/hexdump.c&quot;
#include &quot;../tools/hexstring.c&quot;
#include &quot;../tools/hexdecode.c&quot;
#include &quot;../tools/synonym.c&quot;
#include &quot;../tools/error.c&quot;
#endif

#ifndef MAKEFILE
#include &quot;../serial/openport.c&quot;
#include &quot;../serial/closeport.c&quot;
#include &quot;../serial/serial.c&quot;
#endif

/*====================================================================*
 *   program variables;
 *--------------------------------------------------------------------*/

typedef struct uart

{
	struct _file_ port;
	char const * string;
	byte mode;
	uint64_t baudrate;
	byte databits;
	byte parity;
	byte stopbits;
	byte flowctrl;
	unsigned flags;
}

uart;

/*====================================================================*
 *   program variables;
 *--------------------------------------------------------------------*/

static const struct _term_ modes [] =

{
	{
		&quot;command&quot;,
		&quot;2&quot;
	},
	{
		&quot;transparent&quot;,
		&quot;1&quot;
	}
};

static const struct _term_ paritybits [] =

{
	{
		&quot;even&quot;,
		&quot;2&quot;
	},
	{
		&quot;none&quot;,
		&quot;0&quot;
	},
	{
		&quot;odd&quot;,
		&quot;1&quot;
	}
};

static const struct _term_ flowctrls [] =

{
	{
		&quot;none&quot;,
		&quot;0&quot;
	},
	{
		&quot;off&quot;,
		&quot;0&quot;
	},
	{
		&quot;on&quot;,
		&quot;1&quot;
	}
};

/*====================================================================*
 *   program constants;
 *--------------------------------------------------------------------*/

#define MODES 		(sizeof (modes) / sizeof (struct _term_))
#define PARITYBITS 	(sizeof (paritybits) / sizeof (struct _term_))
#define FLOWCTRLS 	(sizeof (flowctrls) / sizeof (struct _term_))

/*====================================================================*
 *
 *   void at_command (struct uart * uart);
 *
 *--------------------------------------------------------------------*/

static void at_command (struct uart * uart)

{
	clearcommand ();
	while (*uart-&gt;string)
	{
		insert (*uart-&gt;string++);
	}
	insert ('\r');
	sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
	readcommand (&amp;uart-&gt;port, uart-&gt;flags);
	return;
}

/*====================================================================*
 *
 *   void at_wake (struct uart * uart);
 *
 *   send wake command &quot;+++&quot; to enter command mode;
 *
 *--------------------------------------------------------------------*/

static void at_wake (struct uart * uart)

{
	clearcommand ();
	insert ('+');
	insert ('+');
	insert ('+');
	sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
	readcommand (&amp;uart-&gt;port, uart-&gt;flags);
	mustbe ('O');
	mustbe ('K');
	mustbe ('\r');
	return;
}

/*====================================================================*
 *
 *   void atbr (struct uart * uart);
 *
 *   set serial line parameters;
 *
 *--------------------------------------------------------------------*/

static void atbr (struct uart * uart)

{
	clearcommand ();
	insert ('A');
	insert ('T');
	insert ('B');
	insert ('R');
	decode (&amp;uart-&gt;mode, sizeof (uart-&gt;mode));
	insert (',');
	uart-&gt;baudrate = HTOBE64 (uart-&gt;baudrate);
	decode (&amp;uart-&gt;baudrate, sizeof (uart-&gt;baudrate));
	uart-&gt;baudrate = BE64TOH (uart-&gt;baudrate);
	insert (',');
	decode (&amp;uart-&gt;databits, sizeof (uart-&gt;databits));
	insert (',');
	decode (&amp;uart-&gt;parity, sizeof (uart-&gt;parity));
	insert (',');
	decode (&amp;uart-&gt;stopbits, sizeof (uart-&gt;stopbits));
	insert (',');
	decode (&amp;uart-&gt;flowctrl, sizeof (uart-&gt;flowctrl));
	insert ('\r');
	sendcommand (&amp;uart-&gt;port, uart-&gt;flags);
	readcommand (&amp;uart-&gt;port, uart-&gt;flags);
	mustbe ('O');
	mustbe ('K');
	mustbe ('\r');
	return;
}

/*====================================================================*
 *
 *   void manager (struct uart * uart);
 *
 *   examine flagword in struct uart and perform requested operations
 *   in the order that bits are tested; the order that bits are tested
 *   may be changed as needed;
 *
 *--------------------------------------------------------------------*/

static void manager (struct uart * uart)

{
	if (_anyset (uart-&gt;flags, UART_WAKE))
	{
		at_wake (uart);
	}
	if (_anyset (uart-&gt;flags, UART_COMMAND))
	{
		at_command (uart);
	}
	if (_anyset (uart-&gt;flags, UART_ATBR))
	{
		atbr (uart);
	}
	return;
}

/*====================================================================*
 *
 *   int main (int argc, char const * argv []);
 *
 *
 *
 *
 *--------------------------------------------------------------------*/

int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		&quot;B:c:D:F:m:p:P:q:S:uvw&quot;,
		&quot;&quot;,
		&quot;Atheros Serial Line Device Settings&quot;,
		&quot;B n\tbaud rate is (n) [&quot; LITERAL (UART_BAUDRATE) &quot;]&quot;,
		&quot;c s\tsend custom serial line command (s)&quot;,
		&quot;D n\tuse (n) data bits [&quot; LITERAL (UART_DATABITS) &quot;]&quot;,
		&quot;F n\tflow control is (n) [&quot;LITERAL (UART_FLOWCTRL) &quot;]&quot;,
		&quot;m n\tcommand mode is (n)&quot;,
		&quot;p f\tserial port is (f) [&quot; DEVICE &quot;]&quot;,
		&quot;P n\tuse (n) parity bits [&quot; LITERAL (UART_PARITY) &quot;]&quot;,
		&quot;q\tquiet mode&quot;,
		&quot;S n\tuse (n) stop bits [&quot; LITERAL (UART_STOPBITS) &quot;]&quot;,
		&quot;u\tforce default host port settings [115200 8N1]&quot;,
		&quot;v\tverbose mode&quot;,
		&quot;w\twake device [+++]&quot;,
		(char const *) (0)
	};
	struct uart uart =
	{
		{
			0,
			DEVICE
		},
		(char *)(0),
		UART_MODE,
		UART_BAUDRATE,
		UART_DATABITS,
		UART_PARITY,
		UART_STOPBITS,
		UART_FLOWCTRL,
		0
	};
	signed c;
	if (getenv (UART_PORT))
	{
		uart.port.name = strdup (getenv (UART_PORT));
	}
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'B':
			_setbits (uart.flags, UART_ATBR);
			uart.baudrate = (uint64_t)(uintspec (optarg, 1, ULONG_MAX));
			break;
		case 'c':
			_setbits (uart.flags, UART_COMMAND);
			uart.string = optarg;
			break;
		case 'D':
			_setbits (uart.flags, UART_ATBR);
			uart.databits = (byte)(uintspec (optarg, 7, 8));
			break;
		case 'F':
			_setbits (uart.flags, UART_ATBR);
			uart.flowctrl = (byte)(uintspec (synonym (optarg, flowctrls, FLOWCTRLS), 0, UCHAR_MAX));
			break;
		case 'm':
			_setbits (uart.flags, UART_ATBR);
			uart.mode = (byte)(uintspec (synonym (optarg, modes, MODES), 0, UCHAR_MAX));
		case 'P':
			_setbits (uart.flags, UART_ATBR);
			uart.parity = (byte)(uintspec (synonym (optarg, paritybits, PARITYBITS), 0, UCHAR_MAX));
			break;
		case 'q':
			_setbits (uart.flags, UART_SILENCE);
			break;
		case 'p':
			uart.port.name = optarg;
			break;
		case 'S':
			_setbits (uart.flags, UART_ATBR);
			uart.stopbits = (unsigned)(uintspec (optarg, 1, 2));
			break;
		case 'u':
			_setbits (uart.flags, UART_DEFAULT);
			break;
		case 'v':
			_setbits (uart.flags, UART_VERBOSE);
			break;
		case 'w':
			_setbits (uart.flags, UART_WAKE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc)
	{
		error (1, ENOTSUP, ERROR_TOOMANY);
	}
	openport (&amp;uart.port, uart.flags);
	manager (&amp;uart);
	closeport (&amp;uart.port);
	return (0);
}


</pre>
		<div class='footerlink'>
			[<a href='int64host.c.html' title=' int64host.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='int6kboot.c.html' title=' int6kboot.c '>NEXT</a>]
			</div>
		</body>
	</html>
